var DB = require("../lib/db_mysql").DB;


exports.SignService = function(){
  this.getSignLogList = function(user_id,begin_date,end_date,pageNum,pageSize,cb){
    var db = new DB();
    var params = [];
    var sql = "select * from t_sign_log where 1 = 1";
    sql += " and user_id = ?";
    params.push(user_id);
    if(begin_date){
      sql += " and sdate >= ?";
      params.push(begin_date);
    }
    if(end_date){
      sql += " and sdate <= ?";
      params.push(end_date);
    }
    sql += " order by id ";
    db.queryPage(sql,params,pageNum,pageSize,function(err,result){
      return cb(err,result);
    })
  }
  this.getSignList = function(user_id,begin_date,end_date,pageNum,pageSize,cb){
    var db = new DB();
    var params = [];
    var sql = "select s.init_date,s.dt_am,s.dt_pm,l.dt_am as l_dt_am,l.dt_pm as l_dt_pm ";
    sql += " from t_sign s,t_location l where s.location_id = l.location_id";
    sql += " and s.user_id = ?";
    params.push(user_id);
    if(begin_date){
      sql += " and s.init_date >= ?";
      params.push(begin_date);
    }
    if(end_date){
      sql += " and s.init_date <= ?";
      params.push(end_date);
    }
    sql += " order by s.id ";
    db.queryPage(sql,params,pageNum,pageSize,function(err,result){
      return cb(err,result);
    })
  }
}